import type { CartItem } from "@/types/card";
import { http } from "@/untils/request";

/**
 * 加入购物车
 * @param skuId SKUID
 * @param count 数量
 * @returns 
 */
export const addCartListAPI = (skuId: string, count: number) => {
    return http({
        url: '/member/cart',
        method: 'POST',
        data: {
            skuId,
            count
        }
    })
}

/**
 * 获取购物车列表
 * @returns 
 */
export const getCartListAPI = () => {
    return http<CartItem[]>({
        url: '/member/cart',
        method: 'GET'
    })
}

/**
 * 删除/清空购物车单品
 * @param ids 
 * @returns 
 */
export const deleteCartListAPI = (ids: string[]) => {
    return http({
        url: '/member/cart',
        method: 'DELETE',
        data: {
            ids
        }
    })
}

/**
 * 修改购物车单品
 * @param skuId SKUID
 * @param selected 选中状态 可选参数
 * @param count 商品数量 可选参数
 * @returns 
 */
export const updateCartListAPI = (skuId: string, selected?: boolean, count?: number) => {
    return http({
        url: `/member/cart/${skuId}`,
        method: 'PUT',
        data: {
            selected,
            count
        }
    })
}

/**
 * 修改购物车单品
 * @param skuId SKUID
 * @param selected 选中状态 - 可选参数
 * @param count 商品数量 - 可选参数
 * @returns 
 */
export const changeCartCountAPI = (skuId: string, data: { selected?: boolean, count?: number }) => {
    return http({
        url: `/member/cart/${skuId}`,
        method: 'PUT',
        data
    })
}

/**
 * 购物车全选/取消全选
 * @param data 
 * @returns 
 */
export const changeCartSeleteAllAPI = (data: { selected: boolean }) => {
    return http({
        url: '/member/cart/selected',
        method: 'PUT',
        data
    })
}